﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ESHOP.UTIL;
using ESHOP.Domain;
using ESHOP.DAO;
using E_Shop.Common;

namespace E_Shop
{
    public partial class UsHeader : System.Web.UI.UserControl 
    {
        BuyLeadDAO _buyLeadDao = new BuyLeadDAO();
        SellLeadDao _sellLeadDao = new SellLeadDao();
        private readonly HopthuDAO _Email = new HopthuDAO();
        GioHangDAO _gioHangDao = new GioHangDAO();
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadReference();
        }
        private void LoadReference()
        {
            if (Session[Constants.SESSION_LOGIN] == null)
            {
                lblogin_out.Text = "<a href='Login.aspx' title='Login now' >Log in</a>";              
                
            }
            else
            {
                var user = (ACOUNT)Session[Constants.SESSION_LOGIN];
                var buylists = _buyLeadDao.GetBuyCompany(Acount.MACT);
                var sellLists = _sellLeadDao.GetAllSellByCompanyId(Acount.MACT);
                var mails = _Email.GetListbyCompaniesReceiver_new(Acount.MACT);
                var giohangs = _gioHangDao.GetListBuyCompanyId(Acount.MACT);

                lblogin_out.Text = "<a href='Logout.aspx' title='Log out'>Log out</a>";
                lbsername.Text = "<a href='Logout.aspx' title=''>WellCom " + user.USERNAME + "</a>";
                lbNumberInquiry.Text ="(" +(buylists.Count + sellLists.Count)+")";
                lbNumberMessages.Text = "(" +mails.Count+ ")";
                lbNumberSPCard.Text = "(" +giohangs.Count + ")";
                UpdateUserControl.Update();
            }
            upHeader.Update();
        }
        public ACOUNT Acount
        {
            get
            {
                return Session[Constants.SESSION_LOGIN] as ACOUNT;
            }
            set
            {
                value = Session[Constants.SESSION_LOGIN] as ACOUNT;
            }
        }
    }
}